#include <cstdio>
#include <algorithm>

struct Stu {
    int grade;
    int time;
    int id;
} stus[110];


bool MyCompare(const Stu& a, const Stu& b) {
    if (a.grade != b.grade) {
        return a.grade > b.grade;
    }

    if (a.time != b.time) {
        return a.time < b.time;
    }

    return a.id < b.id;


}

/**
 * 
 * 时间复杂度：O(n)
 * 空间复杂度：O(n)
 * 
 * 插入排序
 * @return
 */
int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        int grade, time, id;
        scanf("%d %d %d", &grade, &time, &id);
        stus[i] = { grade, time, id };
    }

    Stu last = stus[n - 1];
    for (int i = 0; i < n - 1; i++) {
        if (MyCompare(last, stus[i])) {
            for (int j = n - 1; j > i; j--) {
                stus[j] = stus[j - 1];
            }
            stus[i] = last;
            break;
        }
    }

    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", stus[i].grade, stus[i].time, stus[i].id);
    }

    return 0;
}